package com.zhangwei.zk1018.service.impl;

import com.zhangwei.zk1018.entity.Goods;
import com.zhangwei.zk1018.entity.Gtypes;
import com.zhangwei.zk1018.dao.GtypesMapper;
import com.zhangwei.zk1018.service.IGtypesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-10-18
 */
@Service
public class GtypesServiceImpl extends ServiceImpl<GtypesMapper, Gtypes> implements IGtypesService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private GtypesMapper gtypesMapper;
    @Override
    public List<Gtypes> getGtype() {
        List<Gtypes> list = new ArrayList<>();
        Boolean aBoolean = redisTemplate.hasKey("11");
        if (aBoolean){
            list = redisTemplate.opsForList().range("11", 0, -1);
        }else {
                 list = gtypesMapper.getList();
                 redisTemplate.opsForList().rightPushAll("11",list);
                 list = redisTemplate.opsForList().range("11", 0, -1);
        }
        return list;
    }
}
